﻿namespace Leetcode.N0713;
public class Solution
{
    public int NumSubarrayProductLessThanK(int[] nums, int k)
    {
        var left = 0;
        var count = 0;
        var val = 1;
        for (int right = 0; right < nums.Length; right++)
        {
            val = val * nums[right];

            for (; left <= right && val >= k; left++)
            {
                count += right - left;
                val = val / nums[left];
            }
        }

        count += (nums.Length - left) * (1 + (nums.Length - left)) / 2;

        return count;
    }
}